//    Copyright (C) Kherty.  All rights reserved.
using System.Diagnostics.Contracts;
using System.Windows;
using System.Windows.Controls;
using System.Diagnostics;
using System.Windows.Input;

namespace OpenLS.Chart.UI
{
    partial class ChartLineResources
    {
        public ChartLineResources()
        {
            InitializeComponent();
        }

        void OnGridLineLoaded (object sender, object args)
        {
            var e = (FrameworkElement) sender;
            var cm = new ContextMenu();
            cm.Items.Add(new MenuItem
            {
                Command = ApplicationCommands.Delete,
                CommandParameter = AxisElement.GetAxis(e)
            });
            
            e.ContextMenu = cm;
        }
        void OnGridLineMouseDown(object sender, MouseButtonEventArgs args)
        {
            var ee = (IInputElement) sender;
            ee.Focus();
            Contract.Assert(Keyboard.FocusedElement == ee);
            args.Handled = true;
        }

        private void OnDeleteGridLine(object sender, ExecutedRoutedEventArgs e)
        {
            var axis = (Axis) e.Parameter;
            if (axis.MinorGridLines != null)
                axis.MinorGridLines = null;
            else
                axis.MajorGridLines = null;
            e.Handled = true;
        }
    }
}
